package com.林子祺.全名健康管理系统.view.servlet.admin;

import com.林子祺.全名健康管理系统.controller.content.comment.CommentDisp;
import com.林子祺.全名健康管理系统.entity.article.content.comment.CommentData;
import com.林子祺.全名健康管理系统.entity.article.content.comment.CurrentCommentData;
import com.林子祺.全名健康管理系统.util.CommentStructure;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

//用于在管理员模式下显示出所有评论
@WebServlet("/AdminCommentDisplay")
public class ArticleCommentDisplay extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        CommentData.Refresh();
        CommentDisp.allPull();

        int number = 0;
        ArrayList<CommentStructure> comment = new ArrayList<>();
        while(CommentData.OutputCommentData(number)){
            comment.add(new CommentStructure(CurrentCommentData.username,CurrentCommentData.articleName,CurrentCommentData.comment));
            number++;
        }

        req.setAttribute("Comment",comment);
        req.getRequestDispatcher("/content/admin/AdminDisplayComment.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
